home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <dos.h>
- #include <time.h>
- #include "tictac.inc" // graphic definitions
- #include "tictac.img"
- #define BOARDSIZE 4 // DO NOT CHANGE!!!!!!
- #define I asm
- #define MaxX 319 // MAXIMUM DISPLAY COORDINATES
- #define MaxY 199
- typedef unsigned char byte; // easier and shorter
-
- int board[4][4][4];
-
- /* Library functions */
- size_t freadfar(unsigned Segm, unsigned Offs, size_t start, size_t size, char FName[80]);
- void SetColor (byte, byte, byte, byte);
-
- /* local fanctions (in this file */
- void InitBoard(void);
- void DisplBoard(void);
- void PutMove(void);
- void CompMove(int);
- void PutSprite(char Sprite[],int X, int Y,unsigned char BckColor);
- int SetUpMouse(void); // returns 1 if OK 0 otherwise.
- void ShowMouse(void); // mouse cursor on
- void HideMouse(void); // mouse cursor off
- void MoveMouse(unsigned int x, unsigned int y); // set mouse to x/y
- void SetMouseBounds(int x1,int y1,int x2,int y2);
- void SetUpBackgr(void); // set up initial background
- void PutBlock(unsigned char *Sprite,int XPos, int YPos);
- void FillBlock(int x1,int y1, int x2, int y2, unsigned char color);
- void wait_vbi(void); // wait for vertical retrace
- void Quit_Procedure(void);
- int New_Procedure(void);
- int KeepPlaying=1; // global so it's easy to change
- int mouse; // has to be global!!
- void intro(void); // intro to the game!!
- void main(void)
- { int Count; // just a counter
-
- intro();
- randomize();
- asm { // set up VGA 320*200*256
- mov ax, 13h
- int 10h
- }
- for(Count=0;Count<=255;Count++) //set colors
- SetColor(Count,Palette[Count][0],
- Palette[Count][1],
- Palette[Count][2]);
-
- InitBoard();
- mouse=SetUpMouse();
- if(!mouse){ // right now mouse is required!!
- printf("Sorry This program requires a mouse!!!");
- exit(1);
- }
- SetUpBackgr();
- DisplBoard();
- if(mouse) ShowMouse();
- while(KeepPlaying)
- {
- DisplBoard();
- PutMove();
- CompMove(0); // first check for players line!
- if(KeepPlaying) CompMove(1); // now make a move if it's ok!
- }
- KeepPlaying=0;
- while(kbhit()) getch();
- while(!kbhit()&&!KeepPlaying)
- asm {
- mov ax, 03 // get button status
- int 33h
- mov KeepPlaying, bx
- }
- ;
- if(mouse) HideMouse();
-
- asm { // back to text mode
- mov ax, 03h
- int 10h
- }
- }
-
- void DisplBoard(void)
- {
- int x, y, z;
- int tmp=255; // background color
-
- if(mouse) HideMouse();
- for(y=0;(y<BOARDSIZE);y++)
- for(x=0;x<BOARDSIZE;x++)
- { if(tmp==255) // change background
- tmp=10;
- else
- tmp=255;
- for(z=0;z<BOARDSIZE;z++)
- { if(!board[x][y][z])
- PutSprite(Space,x*16+z*11-2*z,(y+1)*44-(z*11)+y*2+z,tmp);
- if(board[x][y][z]==2)
- PutSprite(RedMarble,x*16+z*11-2*z,(y+1)*44-(z*11)+y*2+z,tmp);
- if(board[x][y][z]==1)
- PutSprite(BlueMarble,x*16+z*11-2*z,(y+1)*44-(z*11)+y*2+z,tmp);
- if(board[x][y][z]==3)
- PutSprite(BlueWinning,x*16+z*11-2*z,(y+1)*44-(z*11)+y*2+z,tmp);
- if(board[x][y][z]==4)
- PutSprite(RedWinning,x*16+z*11-2*z,(y+1)*44-(z*11)+y*2+z,tmp);
- if(tmp==255) // change background
- tmp=10;
- else
- tmp=255;
- };
- }
- if(mouse) ShowMouse();
- }
-
- void InitBoard(void)
- {
- int x, y, z;
-
- for(x=0;x<=BOARDSIZE;x++)
- for(y=0;y<BOARDSIZE;y++)
- for(z=0;z<BOARDSIZE;z++)
- board[x][y][z]=0;
- }
-
- void PutMove(void)
- { int x, y, z;
- int X, Y;
- int add=1; /* in case I don't want to make a move
- and started a new game with computer
- being first! */
- loop1:
- asm {
- mov ax, 03 // get button status
- int 33h
- cmp bx, 0 // anything pressed?
- je loop1 // nope!
- }
- loop2:
- asm{
- int 33h // check again until released
- cmp bx, 0
- jne loop2
- mov X, cx
- mov Y, dx
- }
- /********************************************************************\
- | I don't know the formula so it's done by trial & error |
- \********************************************************************/
-
- x=255;
- y=255;
- z=255;
-
- if(X/2+Y<=75&&X/2+Y>=61&&Y>44) { x=0;y=0;z=0; goto add;}
- if(X/2+Y<=74&&X/2+Y>=60&&Y>34&&Y<=44) { x=0;y=0;z=1; goto add;}
- if(X/2+Y<=73&&X/2+Y>=59&&Y>24&&Y<=34) { x=0;y=0;z=2; goto add;}
- if(X/2+Y<=72&&X/2+Y>=58&&Y>14&&Y<=24) { x=0;y=0;z=3; goto add;}
-
- if(X/2+Y<=120&&X/2+Y>=106&&Y>89&&Y<=100) { x=0;y=1;z=0; goto add;}
- if(X/2+Y<=119&&X/2+Y>=105&&Y>79&&Y<=89) { x=0;y=1;z=1; goto add;}
- if(X/2+Y<=118&&X/2+Y>=104&&Y>69&&Y<=79) { x=0;y=1;z=2; goto add;}
- if(X/2+Y<=117&&X/2+Y>=103&&Y>59&&Y<=69) { x=0;y=1;z=3; goto add;}
-
- if(X/2+Y<=165&&X/2+Y>=106&&Y>135&&Y<=146) { x=0;y=2;z=0; goto add;}
- if(X/2+Y<=164&&X/2+Y>=105&&Y>125&&Y<=135) { x=0;y=2;z=1; goto add;}
- if(X/2+Y<=163&&X/2+Y>=104&&Y>115&&Y<=125) { x=0;y=2;z=2; goto add;}
- if(X/2+Y<=162&&X/2+Y>=103&&Y>105&&Y<=115) { x=0;y=2;z=3; goto add;}
-
- if(X/2+Y<=210&&X/2+Y>=106&&Y>181&&Y<=192) { x=0;y=3;z=0; goto add;}
- if(X/2+Y<=209&&X/2+Y>=105&&Y>171&&Y<=181) { x=0;y=3;z=1; goto add;}
- if(X/2+Y<=208&&X/2+Y>=104&&Y>161&&Y<=171) { x=0;y=3;z=2; goto add;}
- if(X/2+Y<=207&&X/2+Y>=103&&Y>151&&Y<=161) { x=0;y=3;z=3; goto add;}
-
- if(X/2+Y<=91&&X/2+Y>=61&&Y>44) { x=1;y=0;z=0; goto add;}
- if(X/2+Y<=90&&X/2+Y>=60&&Y>34&&Y<=44) { x=1;y=0;z=1; goto add;}
- if(X/2+Y<=89&&X/2+Y>=59&&Y>24&&Y<=34) { x=1;y=0;z=2; goto add;}
- if(X/2+Y<=87&&X/2+Y>=58&&Y>14&&Y<=24) { x=1;y=0;z=3; goto add;}
-
- if(X/2+Y<=136&&X/2+Y>=106&&Y>89&&Y<=100) { x=1;y=1;z=0; goto add;}
- if(X/2+Y<=135&&X/2+Y>=105&&Y>79&&Y<=89) { x=1;y=1;z=1; goto add;}
- if(X/2+Y<=134&&X/2+Y>=104&&Y>69&&Y<=79) { x=1;y=1;z=2; goto add;}
- if(X/2+Y<=132&&X/2+Y>=103&&Y>59&&Y<=69) { x=1;y=1;z=3; goto add;}
-
- if(X/2+Y<=181&&X/2+Y>=106&&Y>135&&Y<=146) { x=1;y=2;z=0; goto add;}
- if(X/2+Y<=180&&X/2+Y>=105&&Y>125&&Y<=135) { x=1;y=2;z=1; goto add;}
- if(X/2+Y<=179&&X/2+Y>=104&&Y>115&&Y<=125) { x=1;y=2;z=2; goto add;}
- if(X/2+Y<=178&&X/2+Y>=103&&Y>105&&Y<=115) { x=1;y=2;z=3; goto add;}
-
- if(X/2+Y<=226&&X/2+Y>=106&&Y>181&&Y<=192) { x=1;y=3;z=0; goto add;}
- if(X/2+Y<=225&&X/2+Y>=105&&Y>171&&Y<=181) { x=1;y=3;z=1; goto add;}
- if(X/2+Y<=224&&X/2+Y>=104&&Y>161&&Y<=171) { x=1;y=3;z=2; goto add;}
- if(X/2+Y<=223&&X/2+Y>=103&&Y>151&&Y<=161) { x=1;y=3;z=3; goto add;}
-
- if(X/2+Y<=107&&X/2+Y>=61&&Y>44) { x=2;y=0;z=0; goto add;}
- if(X/2+Y<=106&&X/2+Y>=60&&Y>34&&Y<=44) { x=2;y=0;z=1; goto add;}
- if(X/2+Y<=105&&X/2+Y>=59&&Y>24&&Y<=34) { x=2;y=0;z=2; goto add;}
- if(X/2+Y<=104&&X/2+Y>=58&&Y>14&&Y<=24) { x=2;y=0;z=3; goto add;}
-
- if(X/2+Y<=152&&X/2+Y>=106&&Y>89&&Y<=100) { x=2;y=1;z=0; goto add;}
- if(X/2+Y<=151&&X/2+Y>=105&&Y>79&&Y<=89) { x=2;y=1;z=1; goto add;}
- if(X/2+Y<=150&&X/2+Y>=104&&Y>69&&Y<=79) { x=2;y=1;z=2; goto add;}
- if(X/2+Y<=149&&X/2+Y>=103&&Y>59&&Y<=69) { x=2;y=1;z=3; goto add;}
-
- if(X/2+Y<=197&&X/2+Y>=106&&Y>135&&Y<=146) { x=2;y=2;z=0; goto add;}
- if(X/2+Y<=196&&X/2+Y>=105&&Y>125&&Y<=135) { x=2;y=2;z=1; goto add;}
- if(X/2+Y<=195&&X/2+Y>=104&&Y>115&&Y<=125) { x=2;y=2;z=2; goto add;}
- if(X/2+Y<=194&&X/2+Y>=103&&Y>105&&Y<=115) { x=2;y=2;z=3; goto add;}
-
- if(X/2+Y<=242&&X/2+Y>=106&&Y>181&&Y<=192) { x=2;y=3;z=0; goto add;}
- if(X/2+Y<=241&&X/2+Y>=105&&Y>171&&Y<=181) { x=2;y=3;z=1; goto add;}
- if(X/2+Y<=240&&X/2+Y>=104&&Y>161&&Y<=171) { x=2;y=3;z=2; goto add;}
- if(X/2+Y<=239&&X/2+Y>=103&&Y>151&&Y<=161) { x=2;y=3;z=3; goto add;}
-
- if(X/2+Y<=123&&X/2+Y>=61&&Y>44) { x=3;y=0;z=0; goto add;}
- if(X/2+Y<=122&&X/2+Y>=60&&Y>34&&Y<=44) { x=3;y=0;z=1; goto add;}
- if(X/2+Y<=121&&X/2+Y>=59&&Y>24&&Y<=34) { x=3;y=0;z=2; goto add;}
- if(X/2+Y<=120&&X/2+Y>=58&&Y>14&&Y<=24) { x=3;y=0;z=3; goto add;}
-
- if(X/2+Y<=168&&X/2+Y>=106&&Y>89&&Y<=100) { x=3;y=1;z=0; goto add;}
- if(X/2+Y<=167&&X/2+Y>=105&&Y>79&&Y<=89) { x=3;y=1;z=1; goto add;}
- if(X/2+Y<=166&&X/2+Y>=104&&Y>69&&Y<=79) { x=3;y=1;z=2; goto add;}
- if(X/2+Y<=165&&X/2+Y>=103&&Y>59&&Y<=69) { x=3;y=1;z=3; goto add;}
-
- if(X/2+Y<=213&&X/2+Y>=106&&Y>135&&Y<=146) { x=3;y=2;z=0; goto add;}
- if(X/2+Y<=212&&X/2+Y>=105&&Y>125&&Y<=135) { x=3;y=2;z=1; goto add;}
- if(X/2+Y<=211&&X/2+Y>=104&&Y>115&&Y<=125) { x=3;y=2;z=2; goto add;}
- if(X/2+Y<=210&&X/2+Y>=103&&Y>105&&Y<=115) { x=3;y=2;z=3; goto add;}
-
- if(X/2+Y<=258&&X/2+Y>=106&&Y>181&&Y<=192) { x=3;y=3;z=0; goto add;}
- if(X/2+Y<=257&&X/2+Y>=105&&Y>171&&Y<=181) { x=3;y=3;z=1; goto add;}
- if(X/2+Y<=256&&X/2+Y>=104&&Y>161&&Y<=171) { x=3;y=3;z=2; goto add;}
- if(X/2+Y<=255&&X/2+Y>=103&&Y>151&&Y<=161) { x=3;y=3;z=3; goto add;}
-
- if(X>=436&&X<=550&&Y>=135&&Y<=150) // QUIT BUTTON IS PRESSED
- {if(mouse) HideMouse();
- wait_vbi();
- FillBlock(218,132,276,155,128);
- PutBlock(Quit_Btn,215,135); // Set up Quit_btn coordinates are by trial!!
- wait_vbi();
- if(mouse) ShowMouse();
- delay(500); // just to make it looked pressed
- if(mouse) HideMouse();
- FillBlock(215,135,273,158,134);
- PutBlock(Quit_Btn,218,132); // Set up Quit_btn coordinates are by trial!!
- if(mouse) ShowMouse();
- Quit_Procedure();
- }
-
- if(X>=436&&X<=550&&Y>=167&&Y<=182) // NEW BUTTON IS PRESSED
- {if(mouse) HideMouse();
- wait_vbi();
- FillBlock(218,167,276,187,128);
- PutBlock(New_Btn,215,170); // Set up New_Botton coordinates are by trial!!
- wait_vbi();
- if(mouse) ShowMouse();
- delay(500); // just to make it looked pressed
- if(mouse) HideMouse();
- FillBlock(215,170,276,190,134);
- PutBlock(New_Btn,218,167); // Set up New_btn coordinates are by trial!!
- if(mouse) ShowMouse();
- add=New_Procedure(); }
-
- add:
- if(!add) return; // just exit!!
- if(!board[x][y][z])
- board[x][y][z] = 1;
- else
- goto loop1;
- } // bad but simple!!
- void CompMove(int makemove)
- {
- int x, y, z;
- int xCount,oCount;
- int moved = 0; // flag that computer made a move
-
- /***********************************************************************\
- : Check if the human has any combinations of 3 and close them!! :
- : if the human won then BEEP AND QUIT!!! :
- \***********************************************************************/
-
- for(x=0;x<BOARDSIZE;x++)
- for(y=0;y<BOARDSIZE;y++)
- { for(z=0,xCount=0,oCount=0;z<BOARDSIZE;z++)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(z=0;z<BOARDSIZE;z++) // close it!
- if(!board[x][y][z])
- board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(z=0;z<BOARDSIZE;z++)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- {
- for(z=0;z<BOARDSIZE;z++)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) return;
- }
-
- for(x=0;x<BOARDSIZE;x++)
- for(z=0;z<BOARDSIZE;z++)
- { for(y=0,xCount=0,oCount=0;y<BOARDSIZE;y++)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(y=0;y<BOARDSIZE;y++)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(y=0;y<BOARDSIZE;y++)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(y=0;y<BOARDSIZE;y++)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved)
- return;
- }
-
- for(y=0;y<BOARDSIZE;y++)
- for(z=0;z<BOARDSIZE;z++)
- { for(x=0,xCount=0,oCount=0;x<BOARDSIZE;x++)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(x=0;x<BOARDSIZE;x++)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(x=0;x<BOARDSIZE;x++)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(x=0;x<BOARDSIZE;x++)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) // if He has 3 or I have 3
- return;
- }
- /***********************************************************************\
- : Check for diagonal lines in 2 dimensions only :
- \***********************************************************************/
-
- for(x=0;x<BOARDSIZE;x++)
- { for(y=0,z=0,xCount=0,oCount=0;z<BOARDSIZE;z++,y++)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(y=0,z=0;z<BOARDSIZE;z++,y++)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(y=0,z=0;z<BOARDSIZE;z++,y++)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(y=0,z=0;z<BOARDSIZE;z++,y++)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) // if He has 3 or I have 3
- return;
-
- for(y=BOARDSIZE-1,z=0,xCount=0,oCount=0;z<BOARDSIZE;z++,y--)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(y=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,y--)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(y=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,y--)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(y=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,y--)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) // if He has 3 or I have 3
- return;
- }
-
- for(y=0;y<BOARDSIZE;y++)
- { for(x=0,z=0,xCount=0,oCount=0;z<BOARDSIZE;z++,x++)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(x=0,z=0;z<BOARDSIZE;z++,x++)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(x=0,z=0;z<BOARDSIZE;z++,x++)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(x=0,z=0;z<BOARDSIZE;z++,x++)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) // if He has 3 or I have 3
- return;
-
- for(x=BOARDSIZE-1,z=0,xCount=0,oCount=0;z<BOARDSIZE;z++,x--)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(x=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,x--)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(x=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,x--)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(x=BOARDSIZE-1,z=0;z<BOARDSIZE;z++,x--)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) // if He has 3 or I have 3
- return;
- }
-
- for(z=0;z<BOARDSIZE;z++)
- { for(y=0,x=0,xCount=0,oCount=0;x<BOARDSIZE;x++,y++)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(y=0,x=0;x<BOARDSIZE;x++,y++)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(y=0,x=0;x<BOARDSIZE;x++,y++)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(y=0,x=0;x<BOARDSIZE;x++,y++)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) // if He has 3 or I have 3
- return;
-
- for(y=BOARDSIZE-1,x=0,xCount=0,oCount=0;x<BOARDSIZE;x++,y--)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(y=BOARDSIZE-1,x=0;x<BOARDSIZE;x++,y--)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(y=BOARDSIZE-1,x=0;x<BOARDSIZE;x++,y--)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(y=BOARDSIZE-1,x=0;x<BOARDSIZE;x++,y--)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) // if He has 3 or I have 3
- return;
- }
-
- /***********************************************************************\
- : Check for diagonal lines in 3 dimensions only :
- \***********************************************************************/
- for(x=0,y=0,z=0,xCount=0,oCount=0;x<BOARDSIZE;x++,y++,z++)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(x=0,y=0,z=0;x<BOARDSIZE;x++,y++,z++)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(x=0,y=0,z=0;x<BOARDSIZE;x++,y++,z++)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(x=0,y=0,z=0;x<BOARDSIZE;x++,y++,z++)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) // if He has 3 or I have 3
- return;
-
- for(x=0,y=0,z=BOARDSIZE-1,xCount=0,oCount=0;x<BOARDSIZE;x++,y++,z--)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(x=0,y=0,z=BOARDSIZE-1;x<BOARDSIZE;x++,y++,z--)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(x=0,y=0,z=BOARDSIZE-1;x<BOARDSIZE;x++,y++,z--)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(x=0,y=0,z=BOARDSIZE-1;x<BOARDSIZE;x++,y++,z--)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) // if He has 3 or I have 3
- return;
-
- for(x=0,y=BOARDSIZE-1,z=0,xCount=0,oCount=0;x<BOARDSIZE;x++,y--,z++)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(x=0,y=BOARDSIZE-1,z=0;x<BOARDSIZE;x++,y--,z++)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(x=0,y=BOARDSIZE-1,z=0;x<BOARDSIZE;x++,y--,z++)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(x=0,y=BOARDSIZE-1,z=0;x<BOARDSIZE;x++,y--,z++)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) // if He has 3 or I have 3
- return;
-
- for(x=0,y=BOARDSIZE-1,z=BOARDSIZE-1,xCount=0,oCount=0;x<BOARDSIZE;x++,y--,z--)
- { if(board[x][y][z]==1) xCount++;
- if(board[x][y][z]==2) oCount++; //just make it off count!
- }
- if(((xCount==3&&!oCount)||(oCount==3&&!xCount))&&makemove) // if He has 3 or I have 3
- { for(x=0,y=BOARDSIZE-1,z=BOARDSIZE-1;x<BOARDSIZE;x++,y--,z--)
- if(!board[x][y][z]) board[x][y][z]=2;
- if(oCount==3) oCount++;
- moved = 1;
- }
- if(xCount==4)
- { for(x=0,y=BOARDSIZE-1,z=BOARDSIZE-1;x<BOARDSIZE;x++,y--,z--)
- board[x][y][z]=3;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(oCount==4)
- { for(x=0,y=BOARDSIZE-1,z=BOARDSIZE-1;x<BOARDSIZE;x++,y--,z--)
- board[x][y][z]=4;
- DisplBoard();
- sound(100);
- delay(2000);
- nosound();
- KeepPlaying=0;return;
- }
- if(moved) // if He has 3 or I have 3
- return;
- if(!makemove) return;
- /***********************************************************************\
- : Nothing special to do!!! Just plot the random available space! :
- \***********************************************************************/
-
- do {
- x=rand()%3;
- y=rand()%3;
- z=rand()%3;
- } while(board[x][y][z]);
- board[x][y][z]=2;
- return;
- }
-
- void PutSprite(char Sprite[],int X, int Y,unsigned char BckColor)
- {int Width;
- int Hight;
- int x, y;
- char far *Screen;
-
- Width = Sprite[0];
- Hight = Sprite[1];
-
- Screen=MK_FP(0xA000,0x0000);
- Sprite++;
- Sprite++;
- for(y=0;y<Hight;y++)
- for(x=0;x<Width;x++)
- if((unsigned char)Sprite[x+y*Width]!=0xFF) // if not background!
- Screen[(y+Y)*320+X+x+Width-y]= Sprite[x+y*Width]; // set pixel!
- else
- Screen[(y+Y)*320+X+x+Width-y]= BckColor; // set pixel!
- }
-
- void SetUpBackgr(void)
- { wait_vbi();
- asm {
- mov ax, 0A000h
- mov es, ax
- xor di, di
- mov ax, 128 // background color Have no idea why!
- mov cx, 64000
- rep stosb
- }
-
- PutBlock(Bck_Game,Bck_Game_X,Bck_Game_Y);
- PutBlock(Quit_Btn,218,132); // Set up Quit_btn coordinates are by trial!!
- PutBlock(New_Btn,218,167); // Set up New_btn coordinates are by trial!!
- }
-
- void FillBlock(int x1,int y1, int x2, int y2, unsigned char color)
- {char far *Screen;
- int x,y;
-
- Screen = MK_FP(0xA000,0);
- for(y=y1;y<=y2;y++)
- for(x=x1;x<=x2;x++)
- Screen[y*320+x] = color;
- }
- void PutBlock(unsigned char *Sprite,int XPos, int YPos)
- {
- char far *Data;
- char far *Screen;
- int x,y,i;
- int Width,Hight;
-
- unsigned int DisplOffset;
- unsigned char SpriteWidth;
- Data=Sprite+2;
-
- Screen=MK_FP(0xA000,0); /* display Address!!
- Sorry, this is not a define
- cause you are not supposed to
- change that!!!!! */
- y=YPos;
- x=XPos;
- Width=Sprite[0];
- Hight=Sprite[1];
- for(i=0;i<(Hight*Width);i++)
- {if(x<=MaxX&&y<=MaxY)
- Screen[y*320+x]=Data[i];
- x++;
- if(!((i+1)%Width)&&i)
- { x=XPos;
- y++;
- }
- }
- }
-
- void Quit_Procedure(void) /* This procedure is designed to
- 1st - Quit the program in case
- someone presses a quit button
- return in case a person changes
- his mind */
- { int X, Y;
- char key;
-
- if(mouse) HideMouse();
- FillBlock(57,93,116,114,134); // make shadow
- PutBlock(Yes_Btn,60,90); // Set up Yes_Botton coordinates are by trial!!
- FillBlock(127,93,186,114,134); // make shadow
- PutBlock(No_Btn,130,90); // Set up No_Botton coordinates are by trial!!
-
- SetMouseBounds(120,90,378,111);
-
- if(mouse) ShowMouse();
- while(kbhit())
- getch(); // clear kb buffer
- lp1:
- if(kbhit()) // if you pressed a key then leave the loop
- { key = getch();
- goto ContQuit;
- }
- asm {
- mov ax, 03 // get button status
- int 33h
- cmp bx, 0 // anything pressed?
- je lp1 // nope!
- }
- lp2:
- if(kbhit()) // if you pressed a key then leave the loop
- { key = getch();
- goto ContQuit;
- }
- asm{
- mov ax, 03
- int 33h // check again until released
- cmp bx, 0
- jne lp2
- mov X, cx
- mov Y, dx
- }
- ContQuit:
- if((X>=120&&Y>=90&&X<=238&&Y<111)||key=='y'||key=='Y')
- {
- asm {
- mov ax, 03h
- int 10h
- }
- asm {
- mov ax, 0
- int 33h // reset mouse to clear all that was set!
- }
- exit(0);
- }
- while(kbhit())
- getch(); // clear kb buffer
- if(mouse) HideMouse();
- SetUpBackgr();
- DisplBoard();
- SetMouseBounds(16,11,600,193);
- if(mouse) ShowMouse();
- }
-
- int New_Procedure(void) // Ask for confirmation and start a new game
- { int X, Y;
- char key;
-
- if(mouse) HideMouse();
- FillBlock(57,93,116,114,134); // make shadow
- PutBlock(Comp_Btn,60,90); // Set up Comp_Botton coordinates are by trial!!
- FillBlock(127,93,186,114,134); // make shadow
- PutBlock(Hum_Btn,130,90); // Set up Hum_Botton coordinates are by trial!!
-
- SetMouseBounds(120,90,378,111);
-
- if(mouse) ShowMouse();
- while(kbhit())
- getch(); // clear kb buffer
- lp1:
- if(kbhit()) // if you pressed a key then leave the loop
- { key = getch();
- goto ContNew;
- }
- asm {
- mov ax, 03 // get button status
- int 33h
- cmp bx, 0 // anything pressed?
- je lp1 // nope!
- }
- lp2:
- if(kbhit()) // if you pressed a key then leave the loop
- { key = getch();
- goto ContNew;
- }
- asm{
- mov ax, 03
- int 33h // check again until released
- cmp bx, 0
- jne lp2
- mov X, cx
- mov Y, dx
- }
- ContNew:
- if((X>=120&&Y>=90&&X<=238&&Y<111)||key=='c'||key=='c')
- { while(kbhit())
- getch(); // clear kb buffer
- if(mouse) HideMouse();
- InitBoard();
- SetUpBackgr();
- DisplBoard();
- SetMouseBounds(16,11,600,193);
- if(mouse) ShowMouse();
- return(0);
- }
- while(kbhit())
- getch(); // clear kb buffer
- if(mouse) HideMouse();
- InitBoard();
- SetUpBackgr();
- DisplBoard();
- SetMouseBounds(16,11,600,193);
- if(mouse) ShowMouse();
- return(1);
- }
-
-